const express = require('express');
const router = express.Router();
const mongoose = require('mongoose');
const UserInfo = mongoose.model('UserInfo');
const loginHandler = require('../handlers/loginHandler');

module.exports = function(app) {
    app.use('/', router);
};

router.get('/login', function(req, res, next) {
    console.log('this is from register!!');
    res.send('this is user register');
});

router.post('/login',
    loginHandler.nameEixst,
    loginHandler.loginEixst,
    loginHandler.userLogin
);
router.get('/logout', (req, res, next) => {
    req.session.destroy();
    return res.json({
        err: new Error('session过期!'),
        msg: 'session过期，即将跳转至登录界面！！',
        data: null,
    })
})